//
// 嗨~ o(*￣▽￣*)ブ
// Created by Mokou on 2020/7/14.
//

#import "DBManager.h"
#import "ElecMaterial.h"
#import "ElecSchedule.h"
#import "ElecRelation.h"
#import "ElecDevice.h"
#import "ElecUpgrade.h"

@interface Database : NSObject

+ (Database *)shareInstance;

/**
 * 播放计划数据表
 * */
- (int)countSchedule;
- (NSString *)schedule_insert:(ElecSchedule *)schedule;
- (NSArray *)schedule_insert_multi:(NSArray *)scheduleArr; /** 批量 增 */
- (void)schedule_delete:(NSString *)id;
- (void)schedule_delete_multi:(NSArray *)idArr; /** 批量 删 */
- (void)schedule_update:(ElecSchedule *)schedule;
- (NSArray *)schedule_select:(NSString *)id;
- (NSArray *)schedule_select_page:(int)page pageSize:(int)pageSize; /** 分页 */
- (void)schedule_clear:(NSString *)userId; /** 清除用户所有计划 */ //todo userId实际未使用, 目前全部清除

/**
 * 素材数据表
 * */
- (NSDictionary *)material_insert:(ElecMaterial *)material;
- (NSArray *)material_insert_multi:(NSArray *)materialArr; /** 批量 增 */
- (void)material_delete:(NSString *)id;
- (void)material_delete_multi:(NSArray *)idArr; /** 批量 删 */
- (void)material_update:(ElecMaterial *)material;
- (NSArray *)material_select:(NSString *)id;
- (NSArray *)material_select_all;
- (NSArray *)material_select_page:(int)page pageSize:(int)pageSize; /** 分页 */
- (NSArray *)material_select_md5:(NSString *)md5; /** 通过MD5查找 用于素材复用 */

/**
 * 计划素材关系数据表
 * */
- (void)relation_insert:(ElecRelation *)relation;
- (void)relation_insert_multi:(NSArray *)relationArr; /** 批量 增 */
- (void)relation_delete:(NSString *)id;
- (void)relation_delete_multi:(NSArray *)idArr; /** 批量 删 */
- (void)relation_delete_by_s_id:(NSString *)s_id;
- (void)relation_delete_by_m_id:(NSString *)m_id;
- (void)relation_delete_by_s_id_and_m_id:(NSString *)s_id m_id:(NSString *)m_id;
- (void)relation_update_order:(ElecRelation *)relation;
- (NSArray *)relation_select:(NSString *)id;
- (NSArray *)relation_select_page:(int)page pageSize:(int)pageSize; /** 分页 */
- (NSArray *)relation_select_by_s_id:(NSString *)s_id;
- (NSArray *)relation_select_by_m_id:(NSString *)m_id;

/**
 * 临时保存用户选择的相册素材信息
 * */
- (void)tempMedia_insert:(ElecMaterial *)material;
- (void)tempMedia_delete:(NSString *)content;
- (NSArray *)tempMedia_select:(NSString *)content;

/**
 * 设备数据表
 * */
- (void)device_store:(NSArray *)deviceArr;
- (void)device_delete:(NSString *)userId boxSn:(NSString *)boxSn;
- (void)device_clear:(NSString *)userId;
- (NSArray *)device_query:(NSString *)userId;
- (ElecDevice *)device_select_by_boxSn:(NSString *)boxSn;

/**
 * 设备升级数据表
 * */
- (ElecUpgrade *)upgrade_select:(NSString *)boxSn userId:(NSString *)userId;
- (void)upgrade_create:(ElecUpgrade *)upgrade;
- (void)upgrade_clear:(NSString *)userId;
- (void)upgrade_delete:(NSString *)userId boxSn:(NSString *)boxSn;
- (void)upgrade_download:(NSString *)userId boxSn:(NSString *)boxSn localFilePath:(NSString *)localFilePath md5:(NSString *)md5;
- (BOOL)upgrade_update:(ElecUpgrade *)upgrade;
- (NSArray *)upgrade_select_by_local_path:(NSString *)localPath;
- (NSArray *)upgrade_select_by_userId:(NSString *)userId;

@end
